package zhoufu.sz.sanxiao_check.models;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.webkit.URLUtil;

/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/8/5
 */
public class CheckBook implements Parcelable {
    public String name;

    public String Place_ID;

    public String checkDate;

    public String completeDate;

    public String item_unComplete;

    public String item_complete;

    public String path;

    public String evidence;

    public String remark;

    public String remark2;

    public CheckBook(CheckItemModel item) {
        name = item.getName() + "(地址：" + item.getAddress() + ")";
        checkDate = item.getAddTime();
        completeDate = item.getComplete_Time();
        Place_ID = item.getPlace_No();
        StringBuffer sb1 = new StringBuffer();
        StringBuffer sb2 = new StringBuffer();
        remark = TextUtils.isEmpty(item.getLocalRemark())?item.getRemark():item.getLocalRemark();
        if(!URLUtil.isValidUrl(remark)){
            remark = "file://"+remark;
        }
        remark2 = (TextUtils.isEmpty(item.getLocalRemark2())?item.getRemark2():item.getLocalRemark2());
        if(!URLUtil.isValidUrl(remark2)){
            remark2 = "file://"+remark2;
        }
        evidence = TextUtils.isEmpty(item.getLocalSign())?item.getEvidence():item.getLocalSign();
        if(!URLUtil.isValidUrl(evidence)){
            evidence = "file://"+evidence;
        }
        for (DangerModel dangerModel : item.getDangers()) {
            if (dangerModel.getIs_Ok() != 1) {
                continue;
            }
            if (dangerModel.getDisposeStatus() == 0)//未整改
            {
                String imgs="";
                for (int i = 0; i < dangerModel.getBefore_Imgs().size(); i++) {
                    String path = dangerModel.getBefore_Imgs().get(i).getImg();
                    if(!URLUtil.isValidUrl(path)){
                        path = "file://"+path;
                    }
                    imgs +="<img width=$80$ height=$80$ src=$"+path+"$>&nbsp;&nbsp;&nbsp;";
                }
                sb1.append(dangerModel.getContent() + "(" + dangerModel.getMeasure() + ")<br/>")
                .append(imgs+"<br/>");

            } else {
                String imgs="";
                for (int i = 0; i < dangerModel.getApplying_Imgs().size(); i++) {
                    String path = dangerModel.getApplying_Imgs().get(i).getImg();
                    if(!URLUtil.isValidUrl(path)){
                        path = "file://"+path;
                    }
                    imgs +="<img width=$80$ height=$80$ src=$"+path+"$>&nbsp;&nbsp;&nbsp;";
                }
                sb2.append(dangerModel.getContent() + "(" + dangerModel.getMeasure() + ")<br/>").append(imgs+"<br/>");
            }
        }
        if (sb1.length() == 0) {
            item_unComplete = "无";
        } else {
            item_unComplete = sb1.toString();
        }
        if (sb2.length() == 0) {
            item_complete = "无";
        } else {
            item_complete = sb2.toString();
        }
    }

    public void setPath(String path) {
        this.path = path;
    }

    protected CheckBook(Parcel in) {
        name = in.readString();
        Place_ID = in.readString();
        checkDate = in.readString();
        completeDate = in.readString();
        item_unComplete = in.readString();
        item_complete = in.readString();
        evidence = in.readString();
        remark = in.readString();
        remark2 = in.readString();
    }

    public static final Creator<CheckBook> CREATOR = new Creator<CheckBook>() {
        @Override
        public CheckBook createFromParcel(Parcel in) {
            return new CheckBook(in);
        }

        @Override
        public CheckBook[] newArray(int size) {
            return new CheckBook[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeString(Place_ID);
        dest.writeString(checkDate);
        dest.writeString(completeDate);
        dest.writeString(item_unComplete);
        dest.writeString(item_complete);
        dest.writeString(evidence);
        dest.writeString(remark);
        dest.writeString(remark2);

    }
}
